﻿using System.Collections.Generic;
using System.Linq;
using SolidPrinciples.DependencyInversion.DataAccessLayer;

namespace SolidPrinciples.DependencyInversion.BusinessLayer
{
    public class PointOfSaleTerminal
    {
        private readonly ProductRepository _productRepository = new ProductRepository();
        private readonly List<Product> _products = new List<Product>();

        public IEnumerable<Product> Products
        {
            get { return _products; }
        }

        public decimal SumToPay
        {
            get { return _products.Sum(x => x.Price); }
        }

        public void Register(string productSku, int amount)
        {
            Product product = _productRepository.GetBySku(productSku);

            for (int i = 0; i < amount; i++)
            {
                _products.Add(product);
            }
        }
    }
}